//
//  Date+Addition.swift
//  JourneyThroughTime
//
//  Created by iOS-Czz on 2023/11/6.
//

import Foundation
extension Date {
    static func formatTime(inputTime: String) -> String? {
           let formatter = DateFormatter()
           formatter.dateFormat = "HH:mm"
           
           if let date = formatter.date(from: inputTime) {
               formatter.dateFormat = "hh:mm a"
               return formatter.string(from: date)
           }
           
           return nil // 如果时间格式无效
       }
    func toString(format: String = "yyyy-MM-dd HH:mm:ss") -> String {
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = format
            return dateFormatter.string(from: self)
        }
}
